package com.project.server.service.estates.impl;

import com.project.common.core.domain.BaseServer;
import com.project.common.utils.StringUtils;
import com.project.server.domain.estates.TEstatesAssets;
import com.project.server.mapper.estates.TEstatesAssetsMapper;
import com.project.server.service.estates.ITEstatesAssetsService;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 物业管理资产管理Service业务层处理
 *
 * @author project
 * @date 2021-06-28
 */
@Service
public class TEstatesAssetsServiceImpl extends BaseServer implements ITEstatesAssetsService {

    private static final Logger log = LoggerFactory.getLogger(TEstatesAssetsServiceImpl.class);

    @Resource
    private TEstatesAssetsMapper tEstatesAssetsMapper;

    /**
     * 查询运营管理应急处理
     *
     * @param assetsNum 运营管理应急处理
     * @return 运营管理应急处理
     */
    @Override
    public TEstatesAssets selectTEstatesAssetsByNum(Long assetsNum) {
        return tEstatesAssetsMapper.selectTEstatesAssetsByNum(assetsNum);
    }

    /**
     * 查询运营管理应急处理列表
     *
     * @param tEstatesAssets 运营管理应急处理
     * @return 运营管理应急处理
     */
    @Override
    public List<TEstatesAssets> selectTEstatesAssetsList(TEstatesAssets tEstatesAssets) {
        if (tEstatesAssets != null) {
            tEstatesAssets.setAssetsName(StringUtils.validateAndCast(tEstatesAssets.getAssetsName()));
        }
        return tEstatesAssetsMapper.selectTEstatesAssetsList(tEstatesAssets);
    }

    /**
     * 新增运营管理应急处理
     *
     * @param tEstatesAssets 运营管理应急处理
     * @return 结果
     */
    @Override
    public int insertTEstatesAssets(TEstatesAssets tEstatesAssets) {
        super.insert(tEstatesAssets);
        return tEstatesAssetsMapper.insertTEstatesAssets(tEstatesAssets);
    }

    /**
     * 修改运营管理应急处理
     *
     * @param tEstatesAssets 运营管理应急处理
     * @return 结果
     */
    @Override
    public int updateTEstatesAssets(TEstatesAssets tEstatesAssets) {
        super.update(tEstatesAssets);
        return tEstatesAssetsMapper.updateTEstatesAssets(tEstatesAssets);
    }

    /**
     * 批量删除运营管理应急处理
     *
     * @param assetsNums 需要删除的运营管理应急处理编号
     * @return 结果
     */
    @Override
    public int deleteTEstatesAssetsByNums(Long[] assetsNums) {
        return tEstatesAssetsMapper.deleteTEstatesAssetsByNums(assetsNums);
    }

    /**
     * 删除运营管理应急处理信息
     *
     * @param assetsNum 运营管理应急处理
     * @return 结果
     */
    @Override
    public int deleteTEstatesAssetsByNum(Long assetsNum) {
        return tEstatesAssetsMapper.deleteTEstatesAssetsByNum(assetsNum);
    }

    @Override
    public List<TEstatesAssets> selectDeviceList() {
        return tEstatesAssetsMapper.selectDeviceList();
    }

    @Override
    public int operateList(List<TEstatesAssets> collect) {
        tEstatesAssetsMapper.deleteTEstatesAssetsByType("505");
        tEstatesAssetsMapper.deleteTEstatesAssetsByType("2");
        try {
            collect.forEach(tEstatesAssets -> {
                insertTEstatesAssets(tEstatesAssets);
            });
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}
